package com.rulestech.salespro.inventory;

import java.text.DecimalFormat;
import java.util.Date;


/**
 * This class represents the discount information one product can have.
 */
public abstract class Discount implements Cloneable{
	public enum Type{
		SCORE_BASED,
		TRADITIONAL;

	}
 
	
	/**
	 * Discount.Type to be used when deciding the discount
	 */
	private Type discountType;

	private double rate;
	 
	private Date startDateTime;
	 
	private Date endDateTime;
	 
	private DiscountReasonCode discountReasonCode;
	
	private boolean useDefaultSetting = true;

	private long productId;
	
	public Discount(long productId, Type type, boolean useDefaultSetting){
		this.productId = productId;
		this.useDefaultSetting = useDefaultSetting;
		discountType = type;
	}

	public double getRate() {
		return rate;
	}

	public Date getStartDateTime() {
		return startDateTime;
	}

	public Date getEndDateTime() {
		return endDateTime;
	}

	public DiscountReasonCode getDiscountReasonCode() {
		return discountReasonCode;
	}
	
	public void setRate(double rate){
		DecimalFormat twoDForm = new DecimalFormat("#.##");
		this.rate = Double.valueOf(twoDForm.format(rate));
	}
	
	public Discount.Type getDiscountType(){
		return discountType;
	}
	
	public long getProductId(){
		return productId;
	}
	
	public boolean isUseDefaultSetting() {
		return useDefaultSetting;
	}

	@Override
	public Object clone() throws CloneNotSupportedException {
		return super.clone();
	}

	@Override
	public boolean equals(Object obj) {
		return this.rate == ((Discount)obj).getRate();
	}
	
	
}
 
